package at.kaok;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.servlet.http.*;

import at.kaok.betfair.Global;

@SuppressWarnings("serial")
public class TestBetServlet extends HttpServlet {
	static {
		System.setProperty("http.proxyHost", "0.0.0.1");
		System.setProperty("http.proxyPort", "8080");
		System.setProperty("htttps.proxyHost", "0.0.0.1");
		System.setProperty("htttps.proxyPort", "8080");
		System.setProperty("http.proxySet", "true");
		

	}
	
	private static final Logger log = Logger.getLogger(TestBetServlet.class.getName());
	public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
		resp.setContentType("text/plain");
	}
	
	 public void doPost(HttpServletRequest req, HttpServletResponse resp)
             throws IOException {
		 String user = req.getParameter("user");
		 String pwd = req.getParameter("pwd");
		 log.warning("login");
		 log.warning(System.getProperty("http.proxyHost"));

			
		 req.getSession().setAttribute("user", user);
		 req.getSession().setAttribute("pwd",pwd); 
		 req.getSession().setAttribute("bfSession", Global.login(user, pwd));
		 log.warning("BFsession: "+req.getSession().getAttribute("bfSession"));
		 if( req.getSession().getAttribute("bfSession")==null){
			 resp.sendRedirect("/index.jsp");
		 }else{
			 
			 resp.sendRedirect("/BetFairPage.jsp");
			 
		 }
		 
		  
 }

}
